#include<bits/stdc++.h>
#define fir first
#define sec second
using namespace std;
typedef long long LL;
const int MOD=1e9+7;
LL a,b,c,d,A,B;
char temp[1000010];
struct Pair
{
	LL fir,sec;
}n,m;
void init(Pair &ret)
{
	LL len=strlen(temp+1);
	for(LL i=1;i<=len;++i)
	{
		ret.fir=(ret.fir*10%(MOD-1)+temp[i]-'0')%(MOD-1);
		ret.sec=(ret.sec*10%MOD+temp[i]-'0')%MOD;
	}
	return;
}
LL qpow(LL a,LL b)
{
	LL ret=1;
	for(;b;b>>=1,a=a*a%MOD)
		if(b&1)ret=ret*a%MOD;
	return ret;
}
LL inv(LL x)
{
	return qpow(x,MOD-2);
}
int main()
{
	scanf("%s",temp+1);
	init(n);
	scanf("%s",temp+1);
	init(m);
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	if(a!=1)
	{
		A=qpow(a,m.fir-1)*c%MOD;
		B=((qpow(a,m.fir-1)-1)*inv(a-1)%MOD*b%MOD*c%MOD+d)%MOD;
	}
	else
	{
		A=c;
		B=((m.sec-1)*b%MOD*c%MOD+d)%MOD;
	}
	LL ans;
	if(A!=1)
		ans=(qpow(A,n.fir)+(qpow(A,n.fir)-1)*inv(A-1)%MOD*B%MOD)%MOD;
	else
		ans=(n.sec*B+1)%MOD;
	ans=(ans+MOD-d)%MOD*inv(c)%MOD;
	printf("%lld\n",ans);
	return 0;
}
